package com.ls.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ls.config.satoken.SaTokenUtilPy;
import com.ls.entity.BlackList;
import com.ls.entity.Customer;
import com.ls.entity.FeedbackRecord;
import com.ls.entity.SmsTemplate;
import com.ls.mapper.FeedbackRecordMapper;
import com.ls.service.IFeedbackRecordService;
import com.ls.utils.ResultData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户反馈 服务实现类
 * </p>
 *
 * @author pengyu
 * @since 2024-10-12
 */
@Service
public class FeedbackRecordServiceImpl  extends ServiceImpl<FeedbackRecordMapper, FeedbackRecord> implements IFeedbackRecordService {
    /** 新增用户反馈 */
    @Override
    public ResultData add(String content) {
        if (content==null) {
            return ResultData.failure("反馈内容不能为空");
        }
        Customer customer = SaTokenUtilPy.getCustomer();
        FeedbackRecord feedbackRecord;
        feedbackRecord = getOne(new LambdaQueryWrapper<FeedbackRecord>()
                .eq(FeedbackRecord::getCustomerId, customer.getCustomerId())
                .eq(FeedbackRecord::getContent, content));
        if (feedbackRecord != null) {
            return ResultData.failure("反馈内容已经存在");
        }
        feedbackRecord = new FeedbackRecord(content, customer.getCustomerId(), customer.getPhone());
        feedbackRecord.insert();
        return ResultData.successMsg("新增成功");
    }
    /** 查询用户反馈列表 */
    @Override
    public ResultData pageList(String phone,String beginSt,String endSt,Integer pageNum,Integer pageSize) {
        //1 查询出规则列表
        LambdaQueryWrapper<FeedbackRecord> wrapper = new LambdaQueryWrapper<FeedbackRecord>()
                .like(StringUtils.isNotBlank(phone), FeedbackRecord::getPhone, phone)
                .ge(StringUtils.isNotBlank(beginSt), FeedbackRecord::getCreateTime, beginSt)
                .le(StringUtils.isNotBlank(endSt), FeedbackRecord::getCreateTime, endSt)
                .orderByDesc(FeedbackRecord::getCreateTime);
        Page page = new Page(pageNum, pageSize);
        IPage<FeedbackRecord> dtoIPage = this.baseMapper.selectPage(page, wrapper);
        return ResultData.successData(dtoIPage);
    }
}
